package com.example.springmvcdemo5;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Q
 * @create 2025-05-28-9:51
 */
@RequestMapping("/user")
@RestController
public class UserController {
    @RequestMapping("/login")
    public String login(String userName, String password, HttpSession session) {
        //1.判断是否输入值,如果为空，返回false,!，变为真，进入语句
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)) {
            return "账号/密码为空";
        }
        //2.判断是否正确
        if(!"zhangSan".equals(userName) || !"123456".equals(password)) {
            return "账号/密码错误";
        }
        //3.返回比较结果
        session.setAttribute("userName",userName);
        return "";
    }
}
